<?php

declare(strict_types=1);
/**
 *​
 * WxuserController.php
 * 微信用户管理API
 * User：Abell
 * Date：2020/4/18
 * Time：11:11
 */

namespace App\Controller\Abell;

use App\Constants\ErrorCode;
use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
// 业务层
use App\Service\WxuserService;
use Hyperf\Di\Annotation\Inject;
//参数校验
use App\Validate\WxuserValidation;

/**
 * @Controller()
 */
class NewwxuserController extends AbstractController
{

    /**
     * @Inject
     * @var WxuserService
     */
    protected $service;

    /**
     *  原始方案获取token
     * Abell
     * 2020/4/22
     * @RequestMapping(path="/abell/newwxuser/demo_token", methods="get,post")
     */
    public function demoToken(){
        make(WxuserValidation::class)->check($this->request->all(),'loginnew')->response();
        return $this->response->json($this->service->demoToken($this->request->all()));
    }

    /**
     *  EasySDK方案
     * Abell
     * 2020/4/22
     * @RequestMapping(path="/abell/newwxuser/easy_token", methods="get,post")
     */
    public function easyToken(){
        make(WxuserValidation::class)->check($this->request->all(),'loginnew')->response();
        return $this->response->json($this->service->easyToken($this->request->all()));
    }

    /**
     * 支付宝SDK直接获取用户信息 ==> 修改版SDK方案
     * Abell
     * 2020/4/22
     * @RequestMapping(path="/abell/newwxuser/user_info", methods="get,post")
     */
    public function userInfo(){
        $result = $this->service->userInfo();
        return $this->response->json($result);
    }

    /**
     * 小程序new登录注册接口 通过code获取openid 不做二次解密
     * Abell
     * 2020/4/22
     * @RequestMapping(path="/abell/newwxuser/get_token", methods="get,post")
     */
    public function getToken(){
        make(WxuserValidation::class)->check($this->request->all(),'loginnew')->response();
        $result = $this->service->getToken($this->request->all());
        return $this->response->json($result);
    }

    /**
     *  EasySDK方案
     * Abell
     * 2020/4/22
     * @RequestMapping(path="/abell/newwxuser/hello", methods="get,post")
     */
    public function hello(){
        $fish = null;

        $cat = $fish ?? 1; // php7+ 判断是否为null

        $a = 10 ; $b = 11;
        $cc = $a <=> $b;
        var_dump($cc);

        $dd = $this->service->hello(null);
        var_dump($dd);

        $arr = [1,2,3];
        list($a1,$a2,$a3) = $arr;

        var_dump($a1);
        var_dump($a3);

        return $cat;
    }
}
